package com.ruoyi.common.utils;

import com.alibaba.druid.filter.config.ConfigTools;
/**
 * @description druid数据库密码加密
 * @author zhangshu
 * @date 2021-01-29 15:57
 */
public class DruidUtils {
        public static void main(String[] args) throws Exception{
            String password = "root";
            System.out.println("明文密码: " + password);
            String[] keyPair = ConfigTools.genKeyPair(512);
            //私钥
            String privateKey = keyPair[0];
            //公钥
            String publicKey = keyPair[1];
            //用私钥加密后的密文
            password = ConfigTools.encrypt(privateKey, password);
            System.out.println("privateKey:" + privateKey);
            System.out.println("publicKey:" + publicKey);
            System.out.println("password:" + password);
            String decryptPassword = ConfigTools.decrypt(publicKey, password);
            System.out.println("解密后:" + decryptPassword);
        }
    }